from abc import ABC, abstractmethod
from fastapi import Depends, Request
from typing import List
from like.dependencies.database import db
from like.models import system_auth_menu, system_auth_perm, system_auth_role
class ISystemAuthPermService(ABC):
    @classmethod
    @abstractmethod
    async def select_menu_ids_by_role_id(cls, role_ids: List[int]) -> List[int]:
        pass


class SystemAuthPermService:


    @classmethod
    async def select_menu_ids_by_role_id(cls, role_ids: List[int]) -> List[int]:
        """根据角色ID获取菜单ID"""
        role = await db.fetch_one(
            system_auth_role.select()
            .where(system_auth_role.c.id.in_(role_ids), system_auth_role.c.is_disable == 0).limit(1))
        if not role:
            return []
        perms = await db.fetch_all(system_auth_perm.select().where(system_auth_perm.c.role_id.in_(role_ids)))
        return [i.menu_id for i in perms]

    @classmethod
    async def instance(cls):
        """实例化"""
        return cls()